package com.ciquan.server.service.impl;

import com.ciquan.server.bean.Message;
import com.ciquan.server.bean.UnReply;
import com.ciquan.server.dao.MessageMapper;
import com.ciquan.server.service.MessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by kakalee on 15/1/10.
 */
@Service
public class MessageServiceImpl implements MessageService{

    @Resource
    private MessageMapper messageMapper;

    @Override
    public List<Integer> selectWorks() {
        return messageMapper.selectWorks();
    }

    @Override
    public List<Message> selectUserMessage(Integer userId) {
        return messageMapper.selectUserMessage(userId);
    }

    @Override
    public List<Integer> selectUsers(Integer worksId, Integer userId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("worksId", worksId);
        map.put("userId", userId);
        return messageMapper.selectUsers(map);
    }

    @Override
    public List<Message> selectReceiveUsers(Integer worksId, Integer userId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("worksId", worksId);
        map.put("userId", userId);
        return messageMapper.selectReceiveUsers(map);
    }

    @Override
    public List<Message> selectMessage(Integer worksId, Integer userId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("worksId", worksId);
        map.put("userId", userId);
        return messageMapper.selectMessage(map);
    }

    @Override
    public Message selectLastMessage(Integer worksId, Integer userId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("worksId", worksId);
        map.put("userId", userId);
        return messageMapper.selectLastMessage(map);
    }

    @Override
    public int unRead(Integer worksId, Integer userId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("worksId", worksId);
        map.put("userId", userId);
        return messageMapper.unRead(map);
    }

    @Override
    public List<UnReply> unReply(String startTime, String endTime) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        return messageMapper.unReply(map);
    }
}
